import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();

        int[][] scores = new int[N][3];
        int[] totalScores = new int[N];


        for (int i = 0; i < N; i++) {
            int chinese = scanner.nextInt();
            int math = scanner.nextInt();
            int english = scanner.nextInt();

            scores[i][0] = chinese;
            scores[i][1] = math;
            scores[i][2] = english;
            totalScores[i] = chinese + math + english;
        }

        int count = 0;


        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {

                boolean subjectMatch = true;
                for (int k = 0; k < 3; k++) {
                    if (Math.abs(scores[i][k] - scores[j][k]) > 5) {
                        subjectMatch = false;
                        break;
                    }
                }

                boolean totalMatch = Math.abs(totalScores[i] - totalScores[j]) <= 10;

                if (subjectMatch && totalMatch) {
                    count++;
                }
            }
        }

        System.out.println(count);
        scanner.close();
    }
}